﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.迭代器模式
{
    public class NameRepository : IContainer
    {
        public IIterator GetIterator()
        {
            return new NameIterator();
        }
        
    }

    public class NameIterator : IIterator
    {
        private int index = 0;
        private string[] names = { "Robert", "John", "Julie", "Lora" };

        public bool HashNext()
        {
            return index < names.Length;
        }

        public object Next()
        {
            if (HashNext())
            {
                return names[index++];
            }
            return null;
        }
    }
}
